maven profile 动态使用不同环境、依赖打包部署 |
您所在的位置:网站首页 › maven deploy配置 › maven profile 动态使用不同环境、依赖打包部署 |
目录
一、需求二、配置三、激活profile1、使用命令行激活:2、使用IDEA Maven插件激活:3、更多激活profile的方式:
四、示例五、参考地址
一、需求
1、项目需要根据需求,使用不同配置或不同依赖。 2、项目A依赖项目B,项目A仅使用项目B中部分模块,不想引入项目B全部依赖。 二、配置springboot项目B pom.xml: test true dev org.redisson redisson-spring-boot-starter 3.13.1 compile org.redisson redisson-spring-boot-starter 3.13.1 provided1)两处redisson依赖说明: profiles标签下的依赖,只有当相应的profile被激活时,才会导入依赖。scope为compile,使得依赖本项目B的 项目A会导入该redisson依赖。dependencies标签下的依赖,给本项目B正常使用。scope使用provided,表示用于当前项目编译使用,不向下传递,使得依赖本项目B的 项目A不会导入该redisson依赖。参考:maven scope 的作用2)默认激活: true 有该标签的profile默认被激活。但是激活等级最低,如其他profile被激活时,该默认激活会失效。 三、激活profile 1、使用命令行激活:示例: 编译:mvn compile -P dev打包:mvn package -P dev部署(本地仓库):mvn install -P dev发布(远程仓库):mvn deploy -P dev查看当前激活的profile:mvn help:active-profiles参数说明: -P [parameter]:-P可以同时多个参数,如mvn deploy -P test,dev,test和dev都是上面自定义的profile的id值。 2、使用IDEA Maven插件激活:1)勾选想要激活的profile,可以多选。 2)点击Lifecycle下相应的选项。 1、项目B打包发布时激活id为dev的profile:mvn deploy -P dev (1)注意在pom.xml中加入spring-boot-maven-plugin打包插件,这样项目的依赖会一起打包在jar中,否则即使激活了dev的profile,该profile下的依赖并不会被项目A中使用到。 (2)因为是发布到远程仓库,需要添加相关配置。这里的远程仓库是我本地搭建的一个nexus私服,具体如何搭建使用请自行搜索。 com.wy.springboot demo 1.0.0-SNAPSHOT demo Demo project for Spring Boot nexus Nexus Sites http://localhost:8081/repository/maven-snapshots/ org.springframework.boot spring-boot-maven-plugin2、在项目A中引用项目B: com.wy.springboot demo 1.0.0-SNAPSHOT3、查看项目A中所导入的依赖: (1)点击打开项目的依赖图: 4、相关配置: (1) 项目B完整pom.xml 4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE com.wy.springboot demo 1.0.0-SNAPSHOT demo Demo project for Spring Boot 1.8 test true dev org.redisson redisson-spring-boot-starter 3.13.1 compile org.redisson redisson-spring-boot-starter 3.13.1 provided nexus Nexus Sites http://localhost:8081/repository/maven-snapshots/ org.springframework.boot spring-boot-maven-plugin(2)项目A完整pom.xml 4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE com.wuyou.springboot demo2 1.0.0-SNAPSHOT demo2 Demo project for Spring Boot 1.8 nexus nexus http://localhost:8081/repository/maven-snapshots/ true true org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine com.wy.springboot demo 1.0.0-SNAPSHOT org.springframework.boot spring-boot-maven-plugin 五、参考地址 官网参考地址:http://maven.apache.org/pom.html#Profilespom.xml中maven profile的激活方式maven profile动态选择配置文件【IDEA】Maven踩坑:pom文件中的默认profiles不生效+IDEA中Maven的profiles使用说明关于如何激活两个有前置依赖关系的profileMaven 打包趟坑与解法 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |